package pe.edu.sisclas.model.dao.impl;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import pe.edu.sisclas.model.dao.AulaDao;
import pe.edu.sisclas.model.dao.exception.DaoException;
import pe.edu.sisclas.model.domain.Aula;

@Repository
public class AulaDaoImpl implements AulaDao {

	@Autowired
	private SessionFactory sessionFactory;

	@Override
	public Aula getByName(String numero) throws DaoException {
		try{
			Session session = getSessionFactory().getCurrentSession();	
			Aula aula= (Aula)session.createQuery("from Aula a where a.numeroAula=:numero").
					setParameter("numero", numero).uniqueResult();
			return aula;
		}catch(Exception e){
			e.printStackTrace();
			throw DaoException.mensaje("Error al  obtener Aula");
		}
		
	}

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

}
